package jmu.edu.cn.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

import jmu.edu.cn.domain.Classroom;
import jmu.edu.cn.domain.Device;
import jmu.edu.cn.domain.DeviceType;
import jmu.edu.cn.service.DeviceService;
import jmu.edu.cn.service.DeviceServiceImpl;
import jmu.edu.cn.service.DeviceTypeService;
import jmu.edu.cn.service.DeviceTypeServiceImpl;

public class DeviceAction extends ActionSupport {
	private Device dev = new Device();
	private List<Device> devList = new ArrayList<Device>();
	private List<DeviceType> devTypeList = new ArrayList<DeviceType>();
	private List<Classroom> clsList = new ArrayList<Classroom>();
	private String devNum;
	private String devNo;

	public Device getDev() {
		return dev;
	}

	public void setDev(Device dev) {
		this.dev = dev;
	}

	public List<Device> getDevList() {
		return devList;
	}

	public void setDevList(List<Device> devList) {
		this.devList = devList;
	}

	public List<DeviceType> getDevTypeList() {
		return devTypeList;
	}

	public void setDevTypeList(List<DeviceType> devTypeList) {
		this.devTypeList = devTypeList;
	}

	public List<Classroom> getClsList() {
		return clsList;
	}

	public void setClsList(List<Classroom> clsList) {
		this.clsList = clsList;
	}
	
	public String getDevNum() {
		return devNum;
	}

	public void setDevNum(String devNum) {
		this.devNum = devNum;
	}
	
	public String getDevNo() {
		return devNo;
	}

	public void setDevNo(String devNo) {
		this.devNo = devNo;
	}


	public String toAdd() throws Exception {
		DeviceTypeService service=new DeviceTypeServiceImpl();
		devTypeList=service.loadDevType();
		dev.setClsroom(dev.getClsroom());
		return "add_page";
	}

	public String add() throws Exception {
		DeviceService service= new DeviceServiceImpl();
		List<Device> tempList=Device.generateList(Integer.parseInt(devNum), devNo, dev.getClsroom().getClsroomNo());
		service.addDevice(tempList);
		return "loadAllAct";
	}

	public String loadAll() throws Exception {
		DeviceService service = new DeviceServiceImpl();
		devList = service.loadDeviceByClass(dev.getClsroom().getClsroomNo());
		return "list_page";
	}
	
	public String removeDev() throws Exception{
		DeviceService service=new DeviceServiceImpl();
		service.removeDevByClass(dev.getDevNo(), dev.getClsroom().getClsroomNo());
		return "loadAllAct";
	}
}
